home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / shell / xtype.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  88 lines

  1. #define NAME        "xType"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "1"
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        xType
  8.     Author:        SDI (before 1.1 Urban Dominik Müller)
  9.     Distribution:    Freeware
  10.     Description:    Unpack file to stdout
  11.     Compileropts:    -
  12.     Linkeropts:    -l xpkmaster
  13.  
  14.  1.0    : first public release
  15.  1.1   29.11.96 : fixed for new includes
  16. */
  17.  
  18. #include "SDI_defines.h"
  19. #define SDI_TO_ANSI
  20. #include "SDI_ASM_STD_protos.h"
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <proto/xpkmaster.h>
  24.  
  25. #ifdef __MAXON__
  26.   #define __asm
  27. #endif
  28.  
  29. struct Library *XpkBase = 0;
  30. UBYTE errbuf[XPKERRMSGSIZE + 1], *outbuf;
  31. LONG outbuflen;
  32.  
  33. void end(STRPTR text)
  34. {
  35.   if(text)    printf("%s\n", text);
  36.   if(XpkBase)    CloseLibrary(XpkBase);
  37.   exit(text ? 10 : 0);
  38. }
  39.  
  40. void main(int argc, char **argv)
  41. {
  42.   struct XpkFib *xfh;
  43.   STRPTR ptr, last, eol;
  44.   LONG i, len;
  45.  
  46.   if(!(XpkBase = OpenLibrary(XPKNAME, 0)))
  47.     end("Cannot open " XPKNAME);
  48.  
  49.   if(argc < 2 || argv[1][0] == '?')
  50.     end("Usage: xType filename");
  51.  
  52.   for(i = 1; i < argc; i++)
  53.   {
  54.     if(XpkOpenTags(&xfh, XPK_InName, argv[i], XPK_PassThru, TRUE, TAG_DONE))
  55.       end(errbuf);
  56.     if(!(outbuf = (STRPTR) AllocMem(outbuflen = xfh->xf_NLen + XPK_MARGIN, 0)))
  57.       end("Out of memory");
  58.     while((len = XpkRead(xfh, outbuf, XPKLEN_ONECHUNK)) > 0)
  59.     {
  60.       ptr = outbuf;
  61.       last = ptr + len;
  62.       *last = '\n';
  63.  
  64.       do
  65.       {
  66.     if(SetSignal (0L, 0L) & SIGBREAKF_CTRL_C)
  67.     {
  68.       XpkClose(xfh);
  69.       end("***Break");
  70.     }
  71.  
  72.     if(!(eol = strchr(ptr, '\n')))
  73.       eol = last - 1;
  74.     Write(Output(), ptr, 1 + eol - ptr);
  75.     ptr = eol + 1;
  76.       } while(ptr < last);
  77.     }
  78.  
  79.     if(XpkClose(xfh) || len)
  80.       end(errbuf);
  81.  
  82.     FreeMem(outbuf, outbuflen);
  83.     outbuf = NULL;
  84.   }
  85.  
  86.   end(NULL);
  87. }
  88.